{{define "head"}}
<link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/static/css/rules.css?v={{ buildVersion }}">
{{end}}

{{define "content"}}
<div class="container-fluid">
    {{range $storeType := .Sources}}
    {{if $storeType}}
    <h2>{{title $storeType.String}}</h2>
    {{else}}
    <h2>Unknown Type</h2>
    {{end}}
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>Endpoint</th>
            <th>Status</th>
            <th>Announced LabelSets</th>
            <th>Min Time</th>
            <th>Max Time</th>
            <th>Last Successful Health Check</th>
            <th>Last Message</th>
        </tr>
        </thead>
        <tbody>
        {{range $store := index $.Stores $storeType}}
        <tr>
            <td>{{$store.Name}}</td>
            <td class="state">
                {{if not $store.LastError}}
                <span class="alert alert-success state_indicator text-uppercase">up</span>
                {{else}}
                <span class="alert alert-danger state_indicator text-uppercase">down</span>
                {{end}}
            </td>
            <td>
                <table class="table table-bordered">
                <tbody>
                {{range $labelSets := $store.LabelSets}}
                <tr>
                    <td>
                    {{range $label := $labelSets.Labels}}
                        <span class="badge badge-primary">{{$label.Name}}="{{$label.Value}}"</span>
                    {{end}}
                    </td>
                </tr>
                {{end}}
                </tbody>
                </table>
            </td>
            <td>{{formatTimestamp $store.MinTime}}</td>
            <td>{{formatTimestamp $store.MaxTime}}</td>
            <td>{{since $store.LastCheck}} ago</td>
            <td>
                {{if $store.LastError}}
                    <span class="alert alert-danger state_indicator">
                    {{$store.LastError}}
                    </span>
                {{end}}
            </td>
        </tr>
        {{else}}
        <tr>
            <td colspan="7">
                No stores registered
            </td>
        </tr>
        {{end}}
        </tbody>
    </table>
    {{else}}
        <br>
        <div class="alert alert-warning">No stores registered</div>
    {{end}}
</div>
{{end}}
